package com.dragon.english_practice_back.reponse;

import com.fasterxml.jackson.annotation.JsonInclude;
import com.google.gson.Gson;
import lombok.AllArgsConstructor;
import lombok.Data;

@Data
@AllArgsConstructor
@JsonInclude(JsonInclude.Include.NON_NULL)
public class Result<T> {
    int code;
    String message;
    T data;

    public Result(int code, String message) {
        this.code = code;
        this.message = message;
    }
    public static <T> Result<T> ok(String message){
        return new Result<T>(200, message);
    }
    public static <T> Result<T> ok(String message, T data){
        return new Result<>(200, message, data);
    }

    public static <T> Result<T> no(String message) {
        return new Result<>(400, message);
    }
    public static <T> Result<T> no(String message, T data){
        return new Result<T>(400, message, data);
    }

    @Override
    public String toString(){
        return new Gson().toJson(this);
    }
}
